<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\manager;

use app\common\model\PayLog;
use think\Db;
use think\Exception;

class PayLogManager extends BaseManager
{
    public static function record($data,$isTrans=true){
        if ($isTrans)
            Db::startTrans();
        try {
            $payLog = new PayLog();
            $id = $payLog->insertGetId($data);
            if (!$id){
                throw new Exception('请求记录插入失败');
            }
            if ($isTrans)
                Db::commit();
            self::setStatusCode(self::$successCode);
            self::setMessage(self::$successMessage);
            self::setData(['id'=>$id]);
        }catch (Exception $e){
            if ($isTrans)
                Db::rollback();
            self::setStatusCode(self::$failCode);
            self::setMessage($e->getMessage());
        }

        return ['code'=>self::getStatusCode(),'message'=>self::getMessage(),'data'=>self::getData()];
    }

    public static function modify($id,$data,$isTrans=true)
    {
        if ($isTrans)
            Db::startTrans();
        try {
            if(!PayLog::update($data,['id'=>$id])){
                throw new Exception('修改失败');
            }
            if ($isTrans)
                Db::commit();
            self::setStatusCode(self::$successCode);
            self::setMessage(self::$successMessage);
            self::setData(['id'=>$id]);
        }catch (Exception $e){
            if ($isTrans)
                Db::rollback();
            self::setStatusCode(self::$failCode);
            self::setMessage($e->getMessage());
        }

        return ['code'=>self::getStatusCode(),'message'=>self::getMessage(),'data'=>self::getData() ];

    }

}